<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2023/6/6
 * Time: 9:11
 */

namespace App\Rep;


use App\Models\Appendance;
use App\Models\Leave;
use GuzzleHttp\Psr7\Request;

class AppendanceRep
{
    //获取考勤设置列表
    public function getAppendanceListRep($params){
        $list = Appendance::Search($params)->first();
        return $list;
    }

    //修改考勤设置
    public function updateAppendanceRep($params){
        $model = Appendance::where('id',$params['id'])->first();
        if(!empty($params['office_hours'])){
            $model->office_hours = $params['office_hours'];
        }
        if(!empty($params['closing_time'])){
            $model->closing_time = $params['closing_time'];
        }
        $model->save();
        return $model;
    }

    //获取请假列表
    public function getLeaveListRep($params){
        $list = Leave::Search($params)->orderBy('id','desc')->paginate($params['per_page']??10);
        return $list;
    }

    /**
     * 添加编辑请假条
     * @param $params
     */
    public function createLeaveRep($params){
        if(!empty($params['id'])){
            $model = Leave::where('id',$params['id'])->first();
        }else{
            $model = new Leave();
        }
        $model->leave_user_id = $params['leave_user_id'];
        $model->info = $params['leave_user_id'];
        $model->start_time = $params['start_time'];
        $model->end_time = $params['end_time'];
        $model->type = $params['type'];
        $model->operator = $params['user_id'];
        $model->save();
        return $model;
    }

    /**
     * 删除请假簿
     * @param $params
     */
    public function delLeaveRep($params){
        $model = Leave::where('id',$params['id'])->first();
        $model->is_del = 1;
        $model->save();
        return $model;
    }


}